package com.fd.dx.sqlprovider;

import com.fd.dx.domain.ZP;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by lenovo on 2018/3/10.
 */
public class ZPProvider {

    public String addZP(ZP zp)
    {
        return new SQL(){{
            INSERT_INTO("public.zp");
            if(zp.getId()!=null)
            {
                VALUES("id", "#{id}");
            }
            if(zp.getName()!=null)
            {
                VALUES("name", "#{name}");
            }
            if(zp.getIdname()!=null)
            {
                VALUES("idname", "#{idname}");
            }
            if(zp.getRname()!=null)
            {
                VALUES("rname", "#{rname}");
            }
            if(zp.getPid()!=null)
            {
                VALUES("pid", "#{pid}");
            }
            if(zp.getRank()!=null)
            {
                VALUES("rank", "#{rank}");
            }
            if(zp.getGene()!=null)
            {
                VALUES("gene", "#{gene}");
            }
            if(zp.getCsrq()!=null)
            {
                VALUES("csrq", "#{csrq}");
            }
            if(zp.getSwrq()!=null)
            {
                VALUES("swrq", "#{swrq}");
            }
            if(zp.getWife()!=null)
            {
                VALUES("wife", "#{wife}");
            }
            if(zp.getWcsrq()!=null)
            {
                VALUES("wcsrq", "#{wcsrq}");
            }
            if(zp.getWswrq()!=null)
            {
                VALUES("wswrq", "#{wswrq}");
            }
            if(zp.getWintr()!=null)
            {
                VALUES("wintr", "#{wintr}");
            }
            if(zp.getAddr()!=null)
            {
                VALUES("addr", "#{addr}");
            }
            if(zp.getLxfs()!=null)
            {
                VALUES("lxfs", "#{lxfs}");
            }
            if(zp.getIntr()!=null)
            {
                VALUES("intr", "#{intr}");
            }
            if(zp.getZi()!=null)
            {
                VALUES("zi", "#{zi}");
            }
            if(zp.getDadd()!=null)
            {
                VALUES("dadd", "#{dadd}");
            }
            if(zp.getGi()!=null)
            {
                VALUES("gi", "#{gi}");
            }
            if(zp.getDwife()!=null)
            {
                VALUES("dwife", "#{dwife}");
            }
            if(zp.getEdu()!=null)
            {
                VALUES("edu", "#{edu}");
            }
            if(zp.getTitle()!=null)
            {
                VALUES("title", "#{title}");
            }
            if(zp.getSchool()!=null)
            {
                VALUES("school", "#{school}");
            }
            if(zp.getHao()!=null)
            {
                VALUES("hao", "#{hao}");
            }
            if(zp.getTname()!=null)
            {
                VALUES("tname", "#{tname}");
            }
            if(zp.getHaschild()!=null)
            {
                VALUES("haschild", "#{haschild}");
            }
        }}.toString();

    }
    public String updateZP(ZP zp)
    {
        return new SQL(){{
            UPDATE("public.zp");
            if(zp.getName()!=null)
            {
                SET("name=#{name}");
            }
            if(zp.getIdname()!=null)
            {
                SET("idname=#{idname}");
            }
            if(zp.getRname()!=null)
            {
                SET("rname=#{rname}");
            }
            if(zp.getPid()!=null)
            {
                SET("pid=#{pid}");
            }
            if(zp.getRank()!=null)
            {
                SET("rank=#{rank}");
            }
            if(zp.getGene()!=null)
            {
                SET("gene=#{gene}");
            }
            if(zp.getCsrq()!=null)
            {
                SET("csrq=#{csrq}");
            }
            if(zp.getSwrq()!=null)
            {
                SET("swrq=#{swrq}");
            }
            if(zp.getWife()!=null)
            {
                SET("wife=#{wife}");
            }
            if(zp.getWcsrq()!=null)
            {
                SET("wcsrq=#{wcsrq}");
            }
            if(zp.getWswrq()!=null)
            {
                SET("wswrq=#{wswrq}");
            }
            if(zp.getWintr()!=null)
            {
                SET("wintr=#{wintr}");
            }
            if(zp.getAddr()!=null)
            {
                SET("addr=#{addr}");
            }
            if(zp.getLxfs()!=null)
            {
                SET("lxfs=#{lxfs}");
            }
            if(zp.getIntr()!=null)
            {
                SET("intr=#{intr}");
            }
            if(zp.getZi()!=null)
            {
                SET("zi=#{zi}");
            }
            if(zp.getDadd()!=null)
            {
                SET("dadd=#{dadd}");
            }
            if(zp.getGi()!=null)
            {
                SET("gi=#{gi}");
            }
            if(zp.getDwife()!=null)
            {
                SET("dwife=#{dwife}");
            }
            if(zp.getEdu()!=null)
            {
                SET("edu=#{edu}");
            }
            if(zp.getTitle()!=null)
            {
                SET("title=#{title}");
            }
            if(zp.getSchool()!=null)
            {
                SET("school=#{school}");
            }
            if(zp.getHao()!=null)
            {
                SET("hao=#{hao}");
            }
            if(zp.getTname()!=null)
            {
                SET("tname=#{tname}");
            }
            if(zp.getHaschild()!=null)
            {
                SET("haschild=#{haschild}");
            }
            WHERE("id = #{id}");
        }}.toString();

    }
    public String deleteZP(Integer id){
        return new SQL()
        {{
            DELETE_FROM("public.zp");
            WHERE("id="+id);
        }}.toString();
    }
}
